#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //子进程
        int cnt = 3;
        while(cnt)
        {
            printf("我是一个子进程,pid: %d , ppid: %d\n",getpid(),getppid());
            sleep(1);
            cnt--;
         } 
        exit(1);
    }   
    int status = 0;
    pid_t rid = waitpid(id,&status,0);
    if(rid > 0)
    {
        printf("wait success , rid: %d , exit code: %d\n",rid,status);
    }else
    {
        printf("wait failed : %d : %s\n",errno,strerror(errno));
    }
    return 0; 
}
